var nowDate = getDay(0);
var calendar = new lCalendar();
var starttimecalendar = new lCalendar();
var endtimecalendar = new lCalendar();
var resdata;
var url;
starttimecalendar.init({
	'trigger': '#startDate',
	'type': 'date',
	'minDate': '2021-01-01',
	'maxDate': '2099-12-31'
});
endtimecalendar.init({
	'trigger': '#endDate',
	'type': 'date',
	'minDate': '2021-01-01',
	'maxDate': '2099-12-31'
});
function ICalendarClick(){
//	onload()
}
$(document).ready(function(){
	var date =new Date()
	var year=date.getFullYear();
	var month=date.getMonth()+1;
	var theday = date.getDate(); 
	if(month>=0&&month<=9){month='0'+month}
	var lastDay=new Date(year,month,0).getDate();
	$('#name').text(sessionStorage.getItem("name"));
	document.getElementById("startDate").value=year+'-'+month+'-'+'01';
	document.getElementById("endDate").value=year+'-'+month+'-'+lastDay;
	$('#searchButton').on('click',function(){
		if($('#startDate').val() > $('#endDate').val()){
			alert("开始日期不能大于结束日期")
		}else{
	/*		console.log($('#startDate').val());
			console.log($('#endDate').val());
			console.log($('#shopcode').val());
			console.log($('#flagSelect').val());*/
			getData();
		}
	});
	getData();
});
function getData(){
	var sendData = {};
	sendData.userid = sessionStorage.getItem("userId");
	sendData.starttime = $('#startDate').val();
	sendData.endtime = $('#endDate').val()
	sendData.shopcode=$('#shopcode').val();
   	sendData.shenheflag=$('#flagSelect').val();
	$.ajax({
		url: "../../shop_open_info/getResult"
		,type:'post'
//		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res.data);
			resdata =res.data;
			setTableList();
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
}

function setTableList(){
	var trStr='';
	$('#tableListDiv div[tableDiv]').remove();
				for (var i = 0; i < resdata.length; i++) {
					if(resdata[i].shenheflag==0){resdata[i].shenheflag="未审核"}
					else if(resdata[i].shenheflag==1){resdata[i].shenheflag="进行中"}
					else if(resdata[i].shenheflag==2){resdata[i].shenheflag="已开业"}
					trStr += '<tr class="thin-border-bottom">'
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].shopcode+'</span></td>'
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;" class="orange" id="'+resdata[i].sno+'">'+resdata[i].shopname+'</td>'//id="'+el+obj+i+'"
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].shenheflag+'</td>'
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].opentime+'</td>'
							+'</tr>'
				}
				$('#tableListDiv').append('<div tableDiv>'
										+'	<div class="widget-box">'
										+'	<div class="widget-body">'
										+'		<div class="widget-main">'
										+'			<div class="clearfix">'
										+'				<div class="widget-main no-padding">'
										+'					<table class="table tabl	e-bordered table-striped">'
										+'						<thead class="thin-border-bottom">'
										+'							<tr>'
										+'								<th style="width: 9%;;padding-left: 0px;padding-right: 0px;">店号</th>'
										+'								<th style="width: 45%;;padding-left: 0px;padding-right: 0px;">店名</th>'
										+'								<th style="width: 20%">状态</th>'
										+'								<th>开业日期</th>'
										+'							</tr>'
										+'						</thead>'
										+'						<tbody>'
										+							trStr
										+'						</tbody>'
										+'					</table>'
										+'				</div>'
										+'			</div>'
										+'		</div>'
										+'	</div>'
										+'</div>'
										+'</div>');
										

	//点击显示详情
	$("tbody td[id]").on("click",null,function(){
		var html = $(this).html();
		var id = $(this).attr("id");
		console.log(id);
		
		$.ajax({
		url: "../../shop_open_info/getSelectBody"
		,type:'post'
		,data:JSON.stringify({"sno":id})
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res.data);
			var  processid=res.data[0].processId;
			url = "shop_open_timeline?processId="+processid+"&sno="+id;//此处拼接内容
		    window.location.href = url;
			/*resdata =res.data;
			setTableList();*/
		},error:function(XMLHttpRequest, textStatus, errorThrown) {
			alert(XMLHttpRequest);
			 alert(textStatus);
			alert(errorThrown);
			 hideloading();
		}		
	});
		/*if(ptype==1){
			url = "work_plan_plansearch?pno="+id;//此处拼接内容
	        window.location.href = url;
		}else{
			url = "work_plan_search?pno="+id;//此处拼接内容
	        window.location.href = url;
		}*/
/*		var value = $(this).text();
		if(value != undefined){
			//tips层-上
			layer.tips(value, '#'+id, {
				tips: [1, '#0FA6D8'] //还可配置颜色
			});	
		}*/
		
	});
}
